package com.definity.toolkit.domain;

import javax.persistence.Column;
import javax.persistence.Embeddable;

@Embeddable
public class Name {

	private String firstName;
	private String middleName;
	private String lastName;
	private String fullName;
	
	public Name() {

	}

	public Name(String firstName, String middleName, String lastName) {
		this.firstName = firstName;
		this.middleName = middleName;
		this.lastName = lastName;
		
		toFullName();
	}

	@Column(nullable=false, length=100)
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
		
		setFullName(toFullName());
	}

	@Column(nullable=true, length=100)
	public String getMiddleName() {
		return middleName;
	}

	public void setMiddleName(String middleName) {
		this.middleName = middleName;
		
		setFullName(toFullName());
	}

	@Column(nullable=false, length=100)
	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
		
		setFullName(toFullName());
	}

	@Column(nullable=false, length=300)
	public String getFullName() {
		return fullName; 
	}
	
	public void setFullName(String fullName) {
		this.fullName = fullName;
	}
	
	private String toFullName() {
		return firstName + (middleName != null && !middleName.isEmpty()? " " + middleName : "") + " " + lastName;
	}
	
}
